package com.kde.crisisdepalabras;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import com.kde.crisisdepalabras.Model.Combat;
import com.kde.crisisdepalabras.Model.Player;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CombatAdapter extends ArrayAdapter<Combat>
{
    private Context context; 
    private int layoutResourceId;    
    private com.kde.crisisdepalabras.Model.Combat data[] = null;
    //public com.kde.crisisdepalabras.Model.Player pplayer = null;
    
    public CombatAdapter(Context context, int layoutResourceId, final ArrayList<Combat> combats)
    {
    	super(context, layoutResourceId, combats);
    	
    	StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = combats.toArray(new Combat[combats.size()]);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	View rowView = inflater.inflate(layoutResourceId, parent, false);
         
    	CombatHolder holder = new CombatHolder();
    	holder.rivalName = (TextView) rowView.findViewById(R.id.txtNamePlayerCombat);
    	holder.rivalSurname = (TextView) rowView.findViewById(R.id.txtSurNamePlayerCombat);
    	holder.round = (TextView) rowView.findViewById(R.id.txtRound);
    	holder.yourScore = (TextView) rowView.findViewById(R.id.txtYourScore);
    	holder.rivalScore = (TextView) rowView.findViewById(R.id.txtRivalScore);

	    Combat combat = data[position];
        holder.rivalName.setText(combat.getPlayer().getName());
        holder.rivalSurname.setText(combat.getPlayer().getSurname());
        holder.round.setText(Integer.toString(combat.getRound()));
        holder.yourScore.setText(Integer.toString(combat.getYourScore()));  
        holder.rivalScore.setText(Integer.toString(combat.getRivalScore()));  

	    return rowView;
    }
    
    static class CombatHolder
    {
    	TextView rivalName;
    	TextView rivalSurname;
    	TextView round;
    	TextView yourScore;
    	TextView rivalScore;
    }
}